package com.it.travel.controller;

import com.it.travel.service.UserService;
import com.it.travel.vo.Params.LoginParams;
import com.it.travel.vo.Params.RegisterParams;
import com.it.travel.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.mail.MessagingException;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("login")
    public Result<?> login(@RequestBody LoginParams loginParams) {
        Result<?> result = userService.login(loginParams);
        return result;
    }

    @RequestMapping("/register")
    public Result<?> register(@RequestBody RegisterParams registerParams) throws MessagingException {
        Result<?> result = userService.register(registerParams);
        return result;
//        System.out.println("registerParams = " + registerParams);
//        return Result.success(null, "测试赛");
    }

    @GetMapping("/active")  // 账号的激活
    public Result<?> active(@RequestParam("username") String username) {
        Result<?> result = userService.active(username);
        return result;
    }
}
